package com.triangle.cashier;

import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

import com.triangle.cashier.adapter.CustomerAdapter;
import com.triangle.cashier.bean.Order;
import com.triangle.cashier.bean.SelectedGoodsItem;
import com.triangle.cashier.tools.ConstUtil;

import java.util.List;

/**
 * 描述：
 * 创建人：zxm
 * 创建时间： 2017/12/12 on 9:08.
 */

public class CustomerDisplay extends Presentation {
    private Context mContext;
    private TextView tv;
    private ListView listView;
    private CustomerAdapter adapter;
    private TextView payWayTextView;//支付方式
    private TextView totalTextView;//合计
    private TextView receivableTextView;//应收
    private TextView realTextView;//实收
    private TextView changeTextView;//找零
    private TextView saleTextView;//折扣
    private Order order;


    public CustomerDisplay(Context outerContext, Display display) {
        super(outerContext, display);
        mContext = outerContext;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.view_display_customer);
        listView = findViewById(R.id.listView);
        adapter = new CustomerAdapter(mContext);
        payWayTextView = findViewById(R.id.pay_way_TV);
        totalTextView = findViewById(R.id.total_TV);
        receivableTextView = findViewById(R.id.receivable_TV);
        realTextView = findViewById(R.id.real_TV);
        changeTextView = findViewById(R.id.change_TV);
        saleTextView = findViewById(R.id.sale_TV);
        listView.setAdapter(adapter);
//        tv = findViewById(R.id.tv);
    }

    /**
     * 设置左侧预购买商品信息
     */
    public void setProductList(Order order) {
        this.order = order;

    }

    public void refresh(Order order) {
        if (order != null) {
            int payWay = order.getPayWay();
            if (payWay == 0) {
                payWayTextView.setText("支付方式:--");
            } else if (payWay == ConstUtil.PayWay.CASH) {
                payWayTextView.setText("支付方式:现金");
            } else if (payWay == ConstUtil.PayWay.ALI_PAY) {
                payWayTextView.setText("支付方式:支付宝");
            } else if (payWay == ConstUtil.PayWay.WE_CHAT) {
                payWayTextView.setText("支付方式:微信");
            } else if (payWay == ConstUtil.PayWay.CTT) {
                payWayTextView.setText("支付方式:村村通");
            } else if (payWay == ConstUtil.PayWay.BACK_CARD) {
                payWayTextView.setText("支付方式:银行卡");
            }
            if (order.getTotal() <= 0) {
                totalTextView.setText("合计:0.0元");
                saleTextView.setText("折扣:00折");
                receivableTextView.setText("应收:0.0元");
                realTextView.setText("实收:0.0元");
                changeTextView.setText("找零:0.0元");

            } else {
                totalTextView.setText("合计:" + order.getTotal() + "元");
                saleTextView.setText("折扣:" + order.getDiscount() + "折");
                receivableTextView.setText("应收:" + order.getReceivablePay() + "元");
                realTextView.setText("实收:" + order.getRealPayStr() + "元");
                changeTextView.setText("找零:" + order.getChange() + "元");
            }
            List<SelectedGoodsItem> list = order.getList();
            adapter.setData(order.getList());
            if (list != null) {
                if (list.size() > 7) {
                    listView.setSelection(list.size() - 7);
                }
            }
        } else {
            totalTextView.setText("合计:0.0元");
            saleTextView.setText("折扣:00折");
            receivableTextView.setText("应收:0.0元");
            realTextView.setText("实收:0.0元");
            changeTextView.setText("找零:0.0元");
            adapter.setData(null);
        }
    }

}